home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / MacPerl5 / pod / modpods / Find.pod < prev    next >
Encoding:
Text File  |  1994-12-26  |  1.1 KB  |  45 lines  |  [TEXT/MPS ]

  1. =head1 NAME
  2.  
  3. find - traverse a file tree
  4.  
  5. =head1 SYNOPSYS
  6.  
  7.     use File::Find;
  8.     find(\&wanted, '/foo','/bar');
  9.     sub wanted { ... }
  10.  
  11. =head1 DESCRIPTION
  12.  
  13. The wanted() function does whatever verificationsyou want.  $dir contains
  14. the current directory name, and $_ the current filename within that
  15. directory.  $name contains C<"$dir/$_">.  You are chdir()'d to $dir when
  16. the function is called.  The function may set $prune to prune the tree.
  17.  
  18. This library is primarily for the C<find2perl> tool, which when fed, 
  19.  
  20.     find2perl / -name .nfs\* -mtime +7 \
  21.     -exec rm -f {} \; -o -fstype nfs -prune
  22.  
  23. produces something like:
  24.  
  25.     sub wanted {
  26.         /^\.nfs.*$/ &&
  27.         (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
  28.         int(-M _) > 7 &&
  29.         unlink($_)
  30.         ||
  31.         ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
  32.         $dev < 0 &&
  33.         ($prune = 1);
  34.     }
  35.  
  36. Set the variable $dont_use_nlink if you're using AFS, since AFS cheats.
  37.  
  38. Here's another interesting wanted function.  It will find all symlinks
  39. that don't resolve:
  40.  
  41.     sub wanted {
  42.     -l && !-e && print "bogus link: $name\n";
  43.     } 
  44.  
  45.